/**
 * @Author: shyn
 * @Description:
 * @File: robot.go //文件名称
 * @Version: 1.0.0
 * @Date: 2022/1/10 17:22  //时间
 * @Software : GoLand //开发软件【可选】
 */
package robot

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net"
	"os/exec"
	"runtime"
	"strings"
)

type Roboter interface {
	say(string)
	run(string)
}

type Robot struct {
	name string
	age  byte
}

func (*Robot) say(say string) string {
	fmt.Println(say)
	return say
}
func (*Robot) run(run string) string {
	fmt.Println(run)
	return run
}

func NewRobot() {
	gin.SetMode(gin.ReleaseMode)
	if gin.Mode() == gin.DebugMode {
		fmt.Println("当前为debug模式")
	} else {
		fmt.Println("欢迎来到\r\nMYROBOT")
	}

	engine := gin.Default()
	fmt.Println(engine)
}

//
//  GetOutBoundIP
//  @Description: 获取当前用户ip
//  @return ip
//  @return err
//
func GetOutBoundIP() (ip string, err error) {
	conn, err := net.Dial("udp", "8.8.8.8:53")
	if err != nil {
		fmt.Println(err)
		return
	}
	localAddr := conn.LocalAddr().(*net.UDPAddr)
	//fmt.Println(localAddr.String())
	ip = strings.Split(localAddr.String(), ":")[0]
	return
}

var commands = map[string]string{
	"windows": "cmd /c start",
	"darwin":  "open",
	"linux":   "xdg-open",
}

var Version = "0.1.0"
//
//  OpenBrowser
//  @Description:  打开浏览器网址
//  @param url
//  @return error
//
func OpenBrowser(uri string) error {
	run, ok := commands[runtime.GOOS]
	fmt.Println(run)
	if !ok {
		return fmt.Errorf("don't know how to open things on %s platform", runtime.GOOS)
	}

	cmd := exec.Command(run, uri)
	return cmd.Start()
}
